/**
 * create by young (young2f@outlook.com) on 2023/4/15
 */
'use strict';

const aedes = require('aedes')();
const server = require('net').createServer(aedes.handle);
const port = 18080;
const fileUtils=require('./app/fileUtils')
class AppBootHook {
    constructor(app) {
        this.app = app;

    }

    async configWillLoad() {

    }

    async didLoad() {
        return true;
    }

    async willReady() {
        return true;
    }

    async didReady() {

        /**
         * 应用已经启动完毕
         */
        return true;
    }

    async serverDidReady() {

        server.listen(port, function () {
            console.log('server started and listening on port ', port);
        });
        aedes.on('client', function (client) {
            console.log('Client Connected: \x1b[33m' + (client ? client.id : client) + '\x1b[0m', 'to broker', aedes.id);
        });

// 客户端断开
        aedes.on('clientDisconnect', function (client) {
            console.log('Client Disconnected: \x1b[31m' + (client ? client.id : client) + '\x1b[0m', 'to broker', aedes.id);
        });
    }
}

module.exports = AppBootHook;
